package com.shy.service.impl;

import com.shy.dao.StudentDao;
import com.shy.dao.impl.StudentDaoImpl;
import com.shy.model.Student;
import com.shy.service.StudentService;
import java.util.List;

/**
 * StudentService接口的实现类，包含了学生相关业务功能的实现
 *

 */
public class StudentServiceImpl implements StudentService {

    StudentDao studentDao = new StudentDaoImpl();

    @Override
    public Student validateLogin(String rollno, String pwd) {

        Student s = studentDao.getOneById(rollno);
        if (null != s && s.getSpassword().equals(pwd)) {
            return s;
        } else {
            return null;
        }
    }

    @Override
    public Student findStudentById(String rollno) {
        return studentDao.getOneById(rollno);
    }

    @Override
    public int registerNewStudent(Student s) {
        
        Student student=studentDao.getOneById(s.getSid());
        if(null==student){
            return studentDao.insert(s);
        }else{
            return -1;
        }
        
    }

    @Override
    public int modifyStudentInfo(Student s) {
        return studentDao.update(s);
    }

    @Override
    public int unregister(String rollno) {
        return studentDao.deleteById(rollno);
    }

    @Override
    public List<Student> findAllStudents() {
        return studentDao.getAll();
    }

    @Override
    public List<Student> findStudentsByBatchName(String batchName) {
        return studentDao.getStudentListByBatchName(batchName);
    }

    @Override
    public List<Student> findStudentsByBatchNameAndPage(String batchName, int pageNo, int pageSize) {
        return studentDao.getStudentListByBatchNameAndPageNo(batchName, pageNo, pageSize);
    }

    @Override
    public int getBatchSize(String batchName){
        return studentDao.getBatchSize(batchName);
    }
}
